<?php

include FCPATH . 'application/controllers/backend/backend.php';

class Simple_entries extends Backend {

    public function __construct() {

        parent::__construct();
        $this->load->model('entry_model');
    }

    public function index() {
        $type = intval($this->uri->segment(4));
        $this->load_stylesheets(array(
            '../js/ueditor/themes/default/ueditor',
            'backend_simple_entries'
        ));

        $this->load_javascripts(array(
            'ueditor/editor_config',
            'ueditor/editor_all_min',
            'backend_simple_entries'
        ));

        $entries = $this->entry_model->records(0, 0, array(array('type', $type)));

        $data = array(
            'entry' => isset($entries[0]) ? $entries[0] : false,
            'type' => $type
        );
        
        $this->set_javascript_variable('TYPE', $type);

        $this->rend('backend/simple_entries_index_view', $data);
    }

    public function show() {

        $id = intval($this->uri->segment(4));

        $type = intval($this->uri->segment(5));

        $data = array(
            'entry' => $this->entry_model->find($id),
            'type' => $type
        );

        if ($data['entry']) {

            $this->set_javascript_variable('entry_id', $data['entry']->id);

            $this->load->model('photo_model');

            $data['photos'] = $this->photo_model->records(0, 0, array(array('album', $data['entry']->album)));
        }

        $this->load_stylesheets('_photos');

        $this->load_javascripts('_photos');

        $this->load->helper('template');

        $this->rend('backend/simple_entries_show_view', $data);
    }

}

